// EditButton.cpp
//
#include "EditButton.h"

#include "MemCheck.h"

using namespace IDS::IDEAS::OpenGLView::GUIElements;

// ------------------------------------------------------------------------------------------------------
EditButton::EditButton()
:	GUIElement(0,0)
{
	width = height = 32;
	image = QImage(":/res/Icons/901.png").scaled(width,height,Qt::KeepAspectRatio,Qt::SmoothTransformation);	
	rect  = image.rect();
	moved = false;
}

// ------------------------------------------------------------------------------------------------------
EditButton::~EditButton()
{ 
}
//-------------------------------------------------------------------------------------------------
QRectF EditButton::boundingRect() const
{
    return QRectF(-width / 2.0, -height / 2.0, width, height);
}

//-------------------------------------------------------------------------------------------------
void EditButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	painter->setRenderHint(QPainter::Antialiasing, true);
	painter->setRenderHint(QPainter::SmoothPixmapTransform, true);

	painter->drawImage( QPointF(-width / 2.0, -height / 2.0), image);
		
	painter->setRenderHint(QPainter::Antialiasing, false);
	painter->setRenderHint(QPainter::SmoothPixmapTransform, true);

	//printf("%.0f %.0f\n",pos().x(),pos().y() );

	GUIElement::paint(painter, option, widget);
}


//-------------------------------------------------------------------------------------------------
void EditButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
	if(event->buttons() & Qt::LeftButton)
		moved = true;

	QGraphicsItem::mouseMoveEvent(event); 
}

//-------------------------------------------------------------------------------------------------
void EditButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
	//if(event->button() == Qt::LeftButton)
	//	startPos = pos();
	//else
		QGraphicsItem::mousePressEvent(event);
		//moved = false;

	event->accept();
}

//-------------------------------------------------------------------------------------------------
void EditButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	//if(event->button() == Qt::LeftButton)
	//{
	//	setPos(startPos);
	//	dragging = false;
	//	event->accept();
	//}
	//else
		QGraphicsItem::mouseReleaseEvent(event);
}

//-------------------------------------------------------------------------------------------------
void EditButton::wheelEvent(QGraphicsSceneWheelEvent *event)
{
	event->accept();
}
